
<script type="text/javascript" src="<?php echo $this->config->item('js_url'); ?>jquery-1.11.0.min.js"></script>

<script>

    var baseURL = "<?php echo base_url() ?>index.php/"

    function load_reg_page()
    {
        window.location = "<?php echo site_url('index.php/welcome/load_register_page')?>";
    }

    function getRoomStatus()
    {
        $.ajax({
            "type" : "GET",
            "url" : baseURL + "AjaxController/room_status",
            "success" : function(response) {
                $("#room_status").html(response);
            },
            "error" : function() { }
        })

        setTimeout("getRoomStatus()", 10000);
    }

    function login()
    {
        var username = $("#usernameLogin").val();
        var password = $("#passwordLogin").val();

        $.ajax({
            "type" : "POST",
            "url"  : baseURL + "AjaxController/loginUser",
            "data" : {user: username, pass: password},
            "success" : function(response)
            {
                window.location = "<?php echo site_url('index.php/welcome/index')?>";
            },
            "error" : function() { }
        })
    }

    function logout()
    {
        window.location = "<?php echo site_url('index.php/AjaxController/logout')?>";
    }

    function check_if_logged()
    {
        var ret = <?php echo '\'' . $this->session->userdata('logged') .'\'' ?>;

        if(ret == '1')
        {
            $("#logginsection").hide();
            $("#logoutsection").show();
            $("#logname").html("Logged in as <?php echo $this->session->userdata('username') ?>");
        }
        else
        {
            $("#logginsection").show();
            $("#logoutsection").hide();
        }
    }

    $(document).ready(function()
    {
        check_if_logged();

        getRoomStatus();
    });

</script>

</body>
</html>